clear all

* Set your directory path here
local root "D:\Understanding_Bank_Payouts"

capture log close
log using "`root'\Code\Logs\Final_code_RCFS\Figure2.log", replace
display "$S_TIME  $S_DATE"

set more off
set varabbrev off, perm

local finalfile_yearly "`root'\Data\Final\Finalfile_yearly.dta" 

capture noisily mkdir "`root'\Results"
capture noisily mkdir "`root'\Results\Final_code_RCFS"
cd "`root'\Results\Final_code_RCFS"

* Figure 2

ssc install logout

use `finalfile_yearly', clear
xtset instkey year

keep if avg_divyieldWY != .

generate constantY1 = (divpshY1 == L.divpshY1) 
replace constantY1 = . if divgrowthY1 == .
replace constantY1 = 1 if divpshY1 == 0 & L.divpshY1 == 0
replace increaseY1 = 1 if divpshY1 > 0 & divpshY1 != . & L.divpshY1 == 0 // Increase if dividends were 0 but are not now.

replace increaseY1 = 0 if constantY1 == 1 | decreaseY1 ==1
replace constantY1 = 0 if increaseY1 == 1 | decreaseY1 ==1
replace decreaseY1 = 0 if increaseY1 == 1 | constantY1 ==1

drop if increaseY1 == . & constantY1 == . & decreaseY1 == .
drop if increaseY1 == . | constantY1 == . | decreaseY1 == .

log close
logout, save(Figure2.txt) excel fix(8) replace: tabstat increaseY1 decreaseY1 constantY1, by(year) 
logout, save(Figure2_nonTARP.txt) excel fix(8) replace: tabstat increaseY1 decreaseY1 constantY1 if tarp_yr == 0, by(year) 

display "$S_TIME  $S_DATE"
capture log close
clear all

exit, clear

